{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "9d95b118",
   "metadata": {},
   "source": [
    "*2022/09/13/week04\n",
    "*python 课堂笔记"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "a8202ce5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "range(0, 5)"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "##上周回顾（range（））：range：范围\n",
    "range(5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "dce7a56b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "1\n",
      "2\n",
      "3\n",
      "4\n"
     ]
    }
   ],
   "source": [
    "for+range决定循环次数\n",
    "for i in range(5):\n",
    "   print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "11695752",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "range(1, 5)"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "range(1,5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "9633f01d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "2\n",
      "3\n",
      "4\n"
     ]
    }
   ],
   "source": [
    "for i in range(1,5):\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "53ae98c0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "range(1, 10, 3)"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "range(1,10,3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "f822b1f6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "4\n",
      "7\n"
     ]
    }
   ],
   "source": [
    "for i in range(1,10,3):\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8495c6ee",
   "metadata": {},
   "outputs": [],
   "source": [
    "#start?stop?stop?"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ec358445",
   "metadata": {},
   "source": [
    "# 本周内容\n",
    "\n",
    "* type():检查类型\n",
    "\n",
    ">1.数值\n",
    ">>1.int\n",
    ">>2.float\n",
    ">>3.complex\n",
    "\n",
    "\n",
    "\n",
    ">2.字符串"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "8974634f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "9 <class 'int'>\n"
     ]
    }
   ],
   "source": [
    "## Number（数值）\n",
    "\n",
    "a=9\n",
    "print(a,type(a))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "2fec970c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "11.5 <class 'float'>\n"
     ]
    }
   ],
   "source": [
    "##float\n",
    "b=11.5\n",
    "print(b,type(b))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "7f6abd4b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(5+3j) <class 'complex'>\n"
     ]
    }
   ],
   "source": [
    "##complex(虚数，复数)\n",
    "c=5+3j\n",
    "print(c,type(c))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9034a611",
   "metadata": {},
   "source": [
    "# 2.字符串（string)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "56f01253",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Alex <class 'str'>\n"
     ]
    }
   ],
   "source": [
    "name=\"Alex\"\n",
    "print(name,type(name))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "fd76e5d4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Alex <class 'str'>\n"
     ]
    }
   ],
   "source": [
    "name='Alex'\n",
    "print(name,type(name))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "4b51f917",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Alex <class 'str'>\n"
     ]
    }
   ],
   "source": [
    "name='''Alex'''\n",
    "print(name,type(name))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "09f0dbe1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"doesn't\""
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"doesn't\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "5e8ba244",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"doesn't\""
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'doesn\\'t'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "260b0442",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "invalid syntax (3729265038.py, line 1)",
     "output_type": "error",
     "traceback": [
      "\u001b[0;36m  Input \u001b[0;32mIn [20]\u001b[0;36m\u001b[0m\n\u001b[0;31m    nfu_news_pages_html=\u001b[0m\n\u001b[0m                        ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m invalid syntax\n"
     ]
    }
   ],
   "source": [
    "nfu_news_pages_html=\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "d72fd89d",
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'nfu_index_pages_html' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "Input \u001b[0;32mIn [21]\u001b[0m, in \u001b[0;36m<cell line: 1>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[43mnfu_index_pages_html\u001b[49m)\n",
      "\u001b[0;31mNameError\u001b[0m: name 'nfu_index_pages_html' is not defined"
     ]
    }
   ],
   "source": [
    "print(nfu_index_pages_html)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bb606365",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 关于"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "ef3ce744",
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'title' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "Input \u001b[0;32mIn [23]\u001b[0m, in \u001b[0;36m<cell line: 1>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mtitle\u001b[49m[:\u001b[38;5;241m6\u001b[39m]\n",
      "\u001b[0;31mNameError\u001b[0m: name 'title' is not defined"
     ]
    }
   ],
   "source": [
    "title[:6]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1a53cafb",
   "metadata": {},
   "outputs": [],
   "source": [
    "##enumerate 枚举，既可以获取到内容，又可以获取到 索引值index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "5b09c237",
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'title' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "Input \u001b[0;32mIn [25]\u001b[0m, in \u001b[0;36m<cell line: 2>\u001b[0;34m()\u001b[0m\n\u001b[1;32m      1\u001b[0m \u001b[38;5;66;03m##利用for循环 遍历文本信息\u001b[39;00m\n\u001b[0;32m----> 2\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m i \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28menumerate\u001b[39m (\u001b[43mtitle\u001b[49m):\n\u001b[1;32m      3\u001b[0m     \u001b[38;5;28mprint\u001b[39m(i,j)\n",
      "\u001b[0;31mNameError\u001b[0m: name 'title' is not defined"
     ]
    }
   ],
   "source": [
    "##利用for循环 遍历文本信息\n",
    "for i in enumerate (title):\n",
    "    print(i,j)\n",
    "  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "857e87ba",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "a85bcb81",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "invalid character '，' (U+FF0C) (2344726808.py, line 3)",
     "output_type": "error",
     "traceback": [
      "\u001b[0;36m  Input \u001b[0;32mIn [32]\u001b[0;36m\u001b[0m\n\u001b[0;31m    for i，j in enumerate(title):\u001b[0m\n\u001b[0m         ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m invalid character '，' (U+FF0C)\n"
     ]
    }
   ],
   "source": [
    "#思考，如何判断一段文本中是否存在“广州”\n",
    "\n",
    "for i，j in enumerate(title):\n",
    "    if j==\"广\"\n",
    "       if title[i+1]==\"州\"\n",
    "        print(\"广州这个词在这段文本中\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "cd692d0b",
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'title' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "Input \u001b[0;32mIn [33]\u001b[0m, in \u001b[0;36m<cell line: 2>\u001b[0;34m()\u001b[0m\n\u001b[1;32m      1\u001b[0m \u001b[38;5;66;03m##page59  in 检查成员对象\u001b[39;00m\n\u001b[0;32m----> 2\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m广州\u001b[39m\u001b[38;5;124m\"\u001b[39m \u001b[38;5;129;01min\u001b[39;00m \u001b[43mtitle\u001b[49m\n",
      "\u001b[0;31mNameError\u001b[0m: name 'title' is not defined"
     ]
    }
   ],
   "source": [
    "##page59  in 检查成员对象\n",
    "\"广州\" in title\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "396ddd97",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "你好,Alex\n"
     ]
    }
   ],
   "source": [
    "print(\"你好\"+\",\"+\"Alex\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "c5a4635f",
   "metadata": {},
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "can only concatenate str (not \"int\") to str",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "Input \u001b[0;32mIn [35]\u001b[0m, in \u001b[0;36m<cell line: 1>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m你好\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;241;43m+\u001b[39;49m\u001b[38;5;241;43m1\u001b[39;49m\u001b[38;5;241m+\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mAlex\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n",
      "\u001b[0;31mTypeError\u001b[0m: can only concatenate str (not \"int\") to str"
     ]
    }
   ],
   "source": [
    "#字符串不可以和数字进行连接\n",
    "print(\"你好\"+1+\"Alex\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "b32624ac",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 <class 'int'>\n",
      "1 <class 'str'>\n"
     ]
    }
   ],
   "source": [
    "print(1,type(1))\n",
    "print(\"1\",type(\"1\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "579e15cc",
   "metadata": {},
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "unsupported operand type(s) for /: 'str' and 'str'",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "Input \u001b[0;32mIn [37]\u001b[0m, in \u001b[0;36m<cell line: 2>\u001b[0;34m()\u001b[0m\n\u001b[1;32m      1\u001b[0m \u001b[38;5;66;03m#字符串不可以用来运算\u001b[39;00m\n\u001b[0;32m----> 2\u001b[0m \u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m3\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;241;43m/\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m2\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\n",
      "\u001b[0;31mTypeError\u001b[0m: unsupported operand type(s) for /: 'str' and 'str'"
     ]
    }
   ],
   "source": [
    "#字符串不可以用来运算\n",
    "\"3\"/\"2\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "3bd85e17",
   "metadata": {},
   "outputs": [],
   "source": [
    "#由于没有分清楚字符串和\n",
    "width=\"16\"\n",
    "heigt=9"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "787c969f",
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'wdith' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "Input \u001b[0;32mIn [44]\u001b[0m, in \u001b[0;36m<cell line: 1>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0m 面积\u001b[38;5;241m=\u001b[39m\u001b[43mwdith\u001b[49m\u001b[38;5;241m*\u001b[39mheigt\n",
      "\u001b[0;31mNameError\u001b[0m: name 'wdith' is not defined"
     ]
    }
   ],
   "source": [
    "面积=wdith*heigt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "a4ad7423",
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name '面积' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "Input \u001b[0;32mIn [45]\u001b[0m, in \u001b[0;36m<cell line: 1>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43m面积\u001b[49m\n",
      "\u001b[0;31mNameError\u001b[0m: name '面积' is not defined"
     ]
    }
   ],
   "source": [
    "面积"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "42ba1a5b",
   "metadata": {},
   "source": [
    "*字符串的方法\n",
    "\n",
    "\n",
    ">1.str.capitalize():可以将首字母转成大写\n",
    "\n",
    ">2.str.count():数量？"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "dd9825b3",
   "metadata": {},
   "outputs": [],
   "source": [
    "name=\"marry\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "61282aa7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Alex'"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name.capitalize()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "id": "2bddb60f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name.count(\"r\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "5de7ff5e",
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'title' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "Input \u001b[0;32mIn [49]\u001b[0m, in \u001b[0;36m<cell line: 1>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mtitle\u001b[49m\n",
      "\u001b[0;31mNameError\u001b[0m: name 'title' is not defined"
     ]
    }
   ],
   "source": [
    "title"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "id": "3c80d837",
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'title' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "Input \u001b[0;32mIn [51]\u001b[0m, in \u001b[0;36m<cell line: 1>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mtitle\u001b[49m\u001b[38;5;241m.\u001b[39mcount(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m新媒体\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n",
      "\u001b[0;31mNameError\u001b[0m: name 'title' is not defined"
     ]
    }
   ],
   "source": [
    "title.count(\"新媒体\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "id": "178db4ab",
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'title' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "Input \u001b[0;32mIn [52]\u001b[0m, in \u001b[0;36m<cell line: 1>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mtitle\u001b[49m\u001b[38;5;241m.\u001b[39msilit(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m坐落于\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n",
      "\u001b[0;31mNameError\u001b[0m: name 'title' is not defined"
     ]
    }
   ],
   "source": [
    "title.silit(\"坐落于\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "62c5a601",
   "metadata": {},
   "outputs": [],
   "source": [
    "text=\"\"\n",
    "粘贴的文本"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f2f9b6fe",
   "metadata": {},
   "outputs": [],
   "source": [
    "##可以搜索停止词字典，进行文本拆分，然后进一步分析\n",
    "text.split(\"。\")\n",
    "#可以找到文本的。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ab1a75b7",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
